package com.asiainfo.iam.tool;


import com.asiainfo.iam.entity.po.ModoTeam;
import com.asiainfo.iam.entity.po.ModoTeamMember;
import com.asiainfo.iam.entity.po.ModoTeamMemberRole;
import com.asiainfo.iam.entity.po.ModoUser;
import com.asiainfo.iam.entity.vo.Organization;
import com.asiainfo.iam.entity.vo.Role;
import com.asiainfo.iam.entity.vo.User;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class ToPo {


    /**
     *  转换team结构
     * @param org
     * @return ModoTeam
     */
    public ModoTeam toModoTeam(Organization org) {
        ModoTeam modoTeam = new ModoTeam();
        modoTeam.setTeamId(org.getId());
        modoTeam.setTeamName(org.getOrgName());
        modoTeam.setParentTeamId(org.getParentCode());
        modoTeam.setParentTeamName(org.getParentName());
        modoTeam.setState("1");
        modoTeam.setVersion(1);
        return modoTeam;
    }
    public ModoUser toModoUser(User user) {
        ModoUser modoUser = new ModoUser();
        modoUser.setId(user.getId());
        modoUser.setUserId(user.getAccount());
        modoUser.setUserName(user.getUserName());
        modoUser.setState("1");
        modoUser.setUserPwd("weqwqeq");
        return modoUser;
    }

    public ModoTeamMemberRole toModoTeamMemberRole(Role  role) {
        ModoTeamMemberRole modoTeamMemberRole = new ModoTeamMemberRole();
        modoTeamMemberRole.setId(role.getRoleId());
        modoTeamMemberRole.setRoleName(role.getRoleName());
    	return  modoTeamMemberRole;
    }

    /**
     *插入绑定团队-角色-用户关系表
     */
    public ModoTeamMember toModoTeamMember(String teamName,String userId,String roleName) {
        ModoTeamMember modoTeamMember = new ModoTeamMember();
        modoTeamMember.setMemberId(UUID.randomUUID().toString().replace("-", ""));
        modoTeamMember.setRoleName(roleName);
        modoTeamMember.setUserId(userId);
        modoTeamMember.setTeamName(teamName);
        modoTeamMember.setState("1");
        modoTeamMember.setVersion(1);
        return modoTeamMember;

    }
}
